﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.admin
{
    public partial class admin_main : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
    //        <ul>
    //    <li id="man_nav_1"  onclick="list_sub_nav(id,'快捷导航')"  class="bg_image_onclick">快捷导航</li>
    //    <li id="man_nav_2"  onclick="list_sub_nav(id,'商品管理')"  class="bg_image">商品管理</li>
    //    <li id="man_nav_3"  onclick="list_sub_nav(id,'订单管理')"  class="bg_image">订单管理</li>
    //    <li id="man_nav_4"  onclick="list_sub_nav(id,'用户管理')"  class="bg_image">用户管理</li>
    //    <li id="man_nav_5"  onclick="list_sub_nav(id,'店铺管理')"  class="bg_image">店铺管理</li>
    //    <li id="man_nav_6"  onclick="list_sub_nav(id,'资讯频道')"  class="bg_image">资讯频道</li>
    //    <li id="man_nav_7"  onclick="list_sub_nav(id,'系统设置')"  class="bg_image">系统设置</li>
    //    <li id="man_nav_8"  onclick="list_sub_nav(id,'模版标签')"  class="bg_image">模版标签</li>
    //    <li id="man_nav_9"  onclick="list_sub_nav(id,'附件管理')"  class="bg_image">附件管理</li>
    //    <li id="man_nav_10"  onclick="list_sub_nav(id,'门店管理')"  class="bg_image">门店管理</li>
    //</ul>
            if (!IsPostBack)
            {
                nav.InnerHtml = GetNavMain();
            }
            
        }
        string GetNavMain()
        {
            string result = "<ul>";
            YXShop.Model.Admin.AdminInfo admin=YXShop.Common.AdministrorManager.Get();
            if(admin!=null)
            {
                string roleString = YXShop.Common.PowerPass.GetAdminRole(admin);
                roleString = Server.UrlDecode(roleString);
                string[] roles = roleString.Split(new char[] { ',' });
                result += "<li id=\"man_nav_1\"  onclick=\"list_sub_nav(id,'快捷导航')\"  class=\"bg_image_onclick\">快捷导航</li>";
                if (isInRole(roles, "001008000"))
                    result += "<li id=\"man_nav_2\"  onclick=\"list_sub_nav(id,'商品管理')\"  class=\"bg_image\">商品管理</li>";
                if (isInRole(roles, "005001001"))
                    result += "<li id=\"man_nav_3\"  onclick=\"list_sub_nav(id,'订单管理')\"  class=\"bg_image\">订单管理</li>";
                if (isInRole(roles, "008000000"))
                    result += "<li id=\"man_nav_4\"  onclick=\"list_sub_nav(id,'用户管理')\"  class=\"bg_image\">用户管理</li>";
                //if (isInRole(roles, "013003001"))
                //    result += "<li id=\"man_nav_5\"  onclick=\"list_sub_nav(id,'店铺管理')\"  class=\"bg_image\">店铺管理</li>";
                if (isInRole(roles, "009001001"))
                    result += "<li id=\"man_nav_6\"  onclick=\"list_sub_nav(id,'资讯频道')\"  class=\"bg_image\">资讯频道</li>";
                if (isInRole(roles, "010001006"))
                    result += "<li id=\"man_nav_7\"  onclick=\"list_sub_nav(id,'系统设置')\"  class=\"bg_image\">系统设置</li>";
                if (isInRole(roles, "011001001"))
                    result += "<li id=\"man_nav_8\"  onclick=\"list_sub_nav(id,'模版标签')\"  class=\"bg_image\">模版标签</li>";
                if (isInRole(roles, "012001001"))
                    result += "<li id=\"man_nav_9\"  onclick=\"list_sub_nav(id,'附件管理')\"  class=\"bg_image\">附件管理</li>";
                if (isInRole(roles, "014001001"))
                    result += "<li id=\"man_nav_10\"  onclick=\"list_sub_nav(id,'门店管理')\"  class=\"bg_image\">门店管理</li>";
                if (isInRole(roles, "015001001"))
                    result += "<li id=\"man_nav_11\"  onclick=\"list_sub_nav(id,'库存管理')\"  class=\"bg_image\">库存管理</li>";
                //if (isInRole(roles, "016001001"))
                //    result += "<li id=\"man_nav_12\"  onclick=\"list_sub_nav(id,'区域中心库存管理')\"  class=\"bg_image\">区域中心库存管理</li>";
                //if (isInRole(roles, "017001001"))
                //    result += "<li id=\"man_nav_13\"  onclick=\"list_sub_nav(id,'门店库存管理')\"  class=\"bg_image\">门店库存管理</li>";
                result += "</ul>";
            }
            return result;
        }
        bool isInRole(string[] roles, string operateCode)
        {
            bool result = false;
            if (roles[0] == "all")
            {
                result = true;
                return result;
            }
            else
            {
                for (int i = 0; i < roles.Length; i++)
                {
                    if (roles[i] == operateCode)
                    {
                        result = true;
                        return result;
                    }
                }
            }
            return result;
        }
    }
}
